package cn.jn.lhm.order.handler;

import cn.jn.lhm.order.entity.Order;
import cn.jn.lhm.order.service.OrderService;
import cn.jn.lhm.utils.JwtUtils;
import cn.jn.lhm.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author LHM
 * @Tips 热爱每一天，奋斗每一天
 * @date 2020/6/15 - 20:03
 */
@RestController
@RequestMapping("/order")
public class OrderHandler {

    @Resource
    private OrderService orderService;


    @GetMapping("/get/order/info/{orderId}")
    public R getOrderInfo(@PathVariable("orderId")String id){
        Order order = orderService.getOrderInfoByOrderNum(id);
        return R.ok().data("data", order);
    }


    @PostMapping("/create/{courseId}")
    public R createOrder(@PathVariable("courseId")String courseId, HttpServletRequest request){
        //创建订单，返回订单Id
        String orderNum = orderService.createOrder(courseId, JwtUtils.getMemberIdByJwtToken(request));
        return R.ok().data("data",orderNum);
    }


}
